package head.first.model.state.demo2;

/**
 * Created by yiyongyao on 2018/2/27.
 * 糖果机状态--已销售状态
 */
public class SoldState implements  State {

    GumballMachine gumballMachine;

    public SoldState(GumballMachine gumballMachine) {
        this.gumballMachine = gumballMachine;
    }

    @Override
    public void insertQuarter(GumballMachine gumballMachine) {

        System.out.println("请等待,正在出糖果!");

    }

    @Override
    public void ejectQuarter(GumballMachine gumballMachine) {
        System.out.println("您已转动曲柄,无法退还钱币!");
    }

    @Override
    public void turnCrank(GumballMachine gumballMachine) {
        System.out.println("多次转动并不能多给糖果!");
    }

    @Override
    public void dispence(GumballMachine gumballMachine) {
        //出糖果
        gumballMachine.releaseBall();
        if(gumballMachine.getCount()>0)
        {
            System.out.println("出糖成功!");
            gumballMachine.setState(gumballMachine.getNoQuarterState());
        }else{
            System.out.println("糖果已经售罄!");
            gumballMachine.setState(gumballMachine.getSoldOutState());
        }


    }
}
